<?php

use App\Http\Controllers\Admin;
use Illuminate\Support\Facades\Route;

//登录
Route::post('login', [Admin\AuthController::class,'login']);
//系统
Route::middleware('auth:admin')->group(function ($route) {
    $route->post('logout', [Admin\AuthController::class,'logout']);
    $route->post('refresh', [Admin\AuthController::class,'refresh']);
    $route->get('systemMenus', [Admin\IndexController::class,'systemMenus']);
    $route->get('webSite', [Admin\IndexController::class,'webSite']);
    //上传
    $route->post('upload', [Admin\UploadController::class,'uploadFile']);
    $route->post('upload/netUrl', [Admin\UploadController::class,'networkImage']);
    //管理员
    $route->get('basic/info', [Admin\BasicController::class,'info']);
    $route->get('basic/logs', [Admin\BasicController::class,'logs']);
    $route->post('basic/update', [Admin\BasicController::class,'update']);
    $route->post('basic/resetPwd', [Admin\BasicController::class,'resetPassword']);
    //内容管理
    $route->prefix('content')->middleware('permission:content.manage')->group(function ($route) {
        //广告
        $route->prefix('kv')->middleware('permission:content.kv')->group(function ($route) {
            $route->get('list', [Admin\Content\AdvController::class,'data']);
            $route->post('store', [Admin\Content\AdvController::class,'store'])->middleware('permission:content.kv.create');
            $route->put('{id}/update', [Admin\Content\AdvController::class,'update'])->middleware('permission:content.kv.edit');
            $route->delete('destroy', [Admin\Content\AdvController::class,'destroy'])->middleware('permission:content.kv.destroy');
        });
        //文章
        $route->prefix('articles')->middleware('permission:content.articles')->group(function ($route) {
            $route->get('list', [Admin\Content\ArticleController::class,'data']);
            $route->post('store', [Admin\Content\ArticleController::class,'store'])->middleware('permission:content.articles.create');
            $route->get('{id}/show', [Admin\Content\ArticleController::class,'show']);
            $route->put('{id}/update', [Admin\Content\ArticleController::class,'update'])->middleware('permission:content.articles.edit');
            $route->delete('destroy', [Admin\Content\ArticleController::class,'destroy'])->middleware('permission:content.articles.destroy');
            $route->post('recover', [Admin\Content\ArticleController::class,'recover'])->middleware('permission:content.articles.recover');
            $route->delete('expurgate', [Admin\Content\ArticleController::class,'expurgate'])->middleware('permission:content.articles.expurgate');
        });
        //文章分类
        $route->prefix('column')->middleware('permission:content.column')->group(function ($route) {
            $route->get('list', [Admin\Content\CategoryController::class,'data']);
            $route->post('store', [Admin\Content\CategoryController::class,'store'])->middleware('permission:content.column.create');
            $route->put('{id}/update', [Admin\Content\CategoryController::class,'update'])->middleware('permission:content.column.edit');
            $route->delete('destroy', [Admin\Content\CategoryController::class,'destroy'])->middleware('permission:content.column.destroy');
        });
        //标签管理
        $route->prefix('tags')->middleware('permission:content.tags')->group(function ($route) {
            $route->get('list', [Admin\Content\TagsController::class, 'data']);
            $route->post('store', [Admin\Content\TagsController::class, 'store'])->middleware('permission:content.tags.create');
            $route->put('{id}/update', [Admin\Content\TagsController::class, 'update'])->middleware('permission:content.tags.edit');
            $route->delete('destroy', [Admin\Content\TagsController::class, 'destroy'])->middleware('permission:content.tags.destroy');
        });
        //导航栏管理
        $route->prefix('nav')->middleware('permission:content.nav')->group(function ($route) {
            $route->get('list', [Admin\Content\NavController::class, 'data']);
            $route->post('store', [Admin\Content\NavController::class, 'store'])->middleware('permission:content.nav.create');
            $route->put('{id}/update', [Admin\Content\NavController::class, 'update'])->middleware('permission:content.nav.edit');
            $route->delete('destroy', [Admin\Content\NavController::class, 'destroy'])->middleware('permission:content.nav.destroy');
        });
        //附件管理
        $route->prefix('files')->middleware('permission:content.files')->group(function ($route) {
            $route->get('list', [Admin\Content\FilesController::class,'data']);
            $route->delete('destroy', [Admin\Content\FilesController::class,'destroy'])->middleware('permission:content.files.destroy');
            $route->post('recover', [Admin\Content\FilesController::class,'recover'])->middleware('permission:content.files.recover');
            $route->delete('expurgate', [Admin\Content\FilesController::class,'expurgate'])->middleware('permission:content.files.expurgate');
        });
        //附件分组管理
        $route->prefix('filesGroup')->group(function ($route) {
            $route->get('list', [Admin\Content\FilesGroupController::class,'data']);
            $route->post('store', [Admin\Content\FilesGroupController::class,'store'])->middleware('permission:content.filesGroup.create');
            $route->put('{id}/update', [Admin\Content\FilesGroupController::class,'update'])->middleware('permission:content.filesGroup.edit');
            $route->delete('destroy', [Admin\Content\FilesGroupController::class,'destroy'])->middleware('permission:content.filesGroup.destroy');
        });
    });
    //系统管理
    $route->prefix('system')->middleware('permission:system.manage')->group(function ($route) {
        //账号管理
        $route->prefix('user')->middleware('permission:system.user')->group(function ($route) {
            $route->get('list', [Admin\System\UserController::class,'data']);
            $route->post('store', [Admin\System\UserController::class,'store'])->middleware('permission:system.user.create');
            $route->put('{id}/update', [Admin\System\UserController::class,'update'])->middleware('permission:system.user.edit');
            $route->put('{id}/resetPwd', [Admin\System\UserController::class,'resetPassword'])->middleware('permission:system.user.resetPassword');
            $route->delete('destroy', [Admin\System\UserController::class,'destroy'])->middleware('permission:system.user.destroy');
        });
        //角色管理
        $route->prefix('role')->middleware('permission:system.role')->group(function ($route) {
            $route->get('list', [Admin\System\RoleController::class,'data']);
            $route->post('store', [Admin\System\RoleController::class,'store'])->middleware('permission:system.role.create');
            $route->put('{id}/update', [Admin\System\RoleController::class,'update'])->middleware('permission:system.role.edit');
            $route->delete('destroy', [Admin\System\RoleController::class,'destroy'])->middleware('permission:system.role.destroy');
            $route->get('{id}/permission', [Admin\System\RoleController::class,'permission'])->middleware('permission:system.role.permission');
            $route->put('{id}/permission', [Admin\System\RoleController::class,'assignPermission'])->middleware('permission:system.role.permission');
        });
        //菜单管理
        $route->prefix('menus')->middleware('permission:system.menus')->group(function ($route) {
            $route->get('list', [Admin\System\MenusController::class,'data']);
            $route->post('store', [Admin\System\MenusController::class,'store'])->middleware('permission:system.menus.create');
            $route->put('{id}/update', [Admin\System\MenusController::class,'update'])->middleware('permission:system.menus.edit');
            $route->delete('destroy', [Admin\System\MenusController::class,'destroy'])->middleware('permission:system.menus.destroy');
        });
        //字典管理
        $route->prefix('dic')->middleware('permission:system.dic')->group(function ($route) {
            $route->get('list', [Admin\System\DicController::class,'data']);
            $route->get('get', [Admin\System\DicController::class,'item']);
            $route->post('store', [Admin\System\DicController::class,'store'])->middleware('permission:system.dic.create');
            $route->put('{id}/update', [Admin\System\DicController::class,'update'])->middleware('permission:system.dic.edit');
            $route->delete('destroy', [Admin\System\DicController::class,'destroy'])->middleware('permission:system.dic.destroy');
        });
        //字典分类
        $route->prefix('dicGroup')->group(function ($route) {
            $route->get('list', [Admin\System\DicGroupController::class,'data']);
            $route->post('store', [Admin\System\DicGroupController::class,'store'])->middleware('permission:system.dicGroup.create');
            $route->put('{id}/update', [Admin\System\DicGroupController::class,'update'])->middleware('permission:system.dicGroup.edit');
            $route->delete('destroy', [Admin\System\DicGroupController::class,'destroy'])->middleware('permission:system.dicGroup.destroy');
        });
        //任务
        $route->prefix('tasks')->group(function ($route) {
            $route->get('list', [Admin\System\TasksController::class,'data']);
        });
        //系统设置
        $route->prefix('config')->middleware('permission:system.config')->group(function ($route) {
            $route->get('data', [Admin\System\ConfigController::class,'data']);
            $route->put('update', [Admin\System\ConfigController::class,'update'])->middleware('permission:system.config.update');
        });
    });
    //运维管理
    $route->prefix('maintain')->middleware('permission:maintain.manage')->group(function ($route) {
        //数据库管理
        $route->prefix('database')->middleware('permission:maintain.database')->group(function ($route) {
            $route->get('list', [Admin\Maintain\DatabaseController::class,'data']);
            $route->get('show', [Admin\Maintain\DatabaseController::class,'show']);
            $route->post('optimize', [Admin\Maintain\DatabaseController::class,'optimize'])->middleware('permission:maintain.database.optimize');
            $route->post('repair', [Admin\Maintain\DatabaseController::class,'repair'])->middleware('permission:maintain.database.repair');
            $route->post('clear', [Admin\Maintain\DatabaseController::class,'clear'])->middleware('permission:maintain.database.clear');
        });
        $route->prefix('logs')->middleware('permission:maintain.logs')->group(function ($route) {
            //登录记录
            $route->get('login/list', [Admin\Logs\LoginLogController::class,'data'])->middleware('permission:maintain.logs.login');
            //访问日志
            $route->get('access/list', [Admin\Logs\AccessLogController::class,'data'])->middleware('permission:maintain.logs.access');
            //操作日志
            $route->get('activity/list', [Admin\Logs\ActivityController::class,'data'])->middleware('permission:maintain.logs.activity');
            //错误日志
            $route->prefix('error')->middleware('permission:maintain.logs.error')->group(function ($route) {
                $route->get('files', [Admin\Logs\ErrorLogController::class,'files']);
                $route->get('list', [Admin\Logs\ErrorLogController::class,'data']);
            });
        });
    });
});
